package com.ftg.learn.chapter07;

import java.util.Scanner;

/**
 * 练习
 *
 * @author lijiaxin
 * @version 1.0
 * @date 2023/8/1 10:04
 */

public class Test01 {

    public static void q1(StringBuffer str) {
        int sum=0;
        StringBuffer str1=new StringBuffer();
        for (int i = 0; i < str.length()-1; i++) {
            if(str.charAt(i)==str.charAt(i+1)){
                str1= str.replace( i+1,i+2,"5");
                sum++;
            }
        }
        System.out.println(str1);
        System.out.println(sum);
    }

    public static void q2(String str){
        int count;
        String str1="";
        int num=0;
        for (int i = 1; i < str.length()-1; i++) {
            if(str.charAt(i)==str.charAt(i+1)){
                num++;
                if(str.charAt(i)==str.charAt(i-1)){
                    str1=str.replace(str.charAt(i),'5');
                    i=i+1;
                }else {
                    i=i;
                }
            }
        }
        System.out.println(str1);
    }


    public static void main(String[] args) {
        StringBuffer str= new StringBuffer("111222233344444");
//        Scanner scanner=new Scanner (System.in);
//        StringBuffer str=scanner.next();
        q1(str);
    }
}
